<?php

class UserController extends Base_Controller
{

   public function init()
    {
    	parent::init();
    }

   
    public function indexAction()
    {
    	$this->_helper->layout->disableLayout();  

    }

    public function createAction()
    {
    	//validate data
    	$validatorChain = new Zend_Validate();
    	$validatorChain->addValidator(new Zend_Validate_NotEmpty());
    	$validatorChain->addValidator(new Zend_Validate_StringLength(2, 20));
    	if (!($validatorChain->isValid($_POST['username'])
    	&& $validatorChain->isValid($_POST['password'])
    	&& $validatorChain->isValid($_POST['nickname']))) {
    		session_start();
    		$_SESSION['error_messages']=$validatorChain->getMessages();    		
    		$this->_redirect("/user");
    	} else {
	    	$authService = Application_Model_UserService::getInstance();	    	
	    	$userInfo = $authService->createUser($_POST['username'], $_POST['password'],$_POST['nickname']);
	    	if ($userInfo != null) {
	    		session_start();
	    		$_SESSION['userinfo']=$userInfo;    		
	       	}
	       	
			$this->_redirect("/");
    	}

    }
    
}

